#!/usr/bin/env bash
STARTTIME=$(date +%s)
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"

# Update test names.
# Since k8s 1.24, GCP PD tests are opt-in through an environment variable. See:
# https://github.com/kubernetes/kubernetes/pull/109541
ENABLE_STORAGE_GCE_PD_DRIVER=yes go generate -mod vendor ./test/extended

# the test names are now contained in test/extended/util/annotate/generated/zz_generated.annotations.go
# A txt file would be more extensible, but Maciej stacked the debt here and he's the same person who will have pay it down
# as we add more images with more tests, so this seems acceptable.
go run -mod vendor ./cmd/openshift-tests render test-report --output-dir=./zz_generated.manifests

# Update mirror mapping from upstream to quay
echo "# This file is generated by hack/update-generated.sh" > test/extended/util/image/zz_generated.txt
go run -mod vendor ./cmd/openshift-tests images --upstream --to-repository quay.io/openshift/community-e2e-images >> test/extended/util/image/zz_generated.txt

os::build::setup_env

OUTPUT_PARENT=${OUTPUT_ROOT:-$OS_ROOT}

# If you hit this, please reduce other tests instead of importing more
if [[ "$( cat "${OUTPUT_PARENT}/test/extended/testdata/bindata.go" | wc -c )" -gt 2500000 ]]; then
    echo "error: extended bindata is $( cat "${OUTPUT_PARENT}/test/extended/testdata/bindata.go" | wc -c ) bytes, reduce the size of the import" 1>&2
    exit 1
fi

ret=$?; ENDTIME=$(date +%s); echo "$0 took $(($ENDTIME - $STARTTIME)) seconds"; exit "$ret"
